package hash;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 十八岁讨厌编程
 * @date 2025/6/27 21:16
 * @PROJECT_NAME leetcode
 * @description
 */

public class Solution454 {


    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> records = new HashMap<>();
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                records.put(nums1[i] + nums2[j], records.getOrDefault(nums1[i] + nums2[j], 0) + 1);
            }
        }

        int result = 0;

        for (int i = 0; i < nums3.length; i++) {
            for (int j = 0; j < nums4.length; j++) {
                Integer count = records.get(0 - nums3[i] - nums4[j]);
                if (count != null) result += count;
            }
        }

        return result;
    }

}
